local huabian = fk.CreateSkill{
  name = "lingling__huabian",
}

Fk:loadTranslationTable{
  ["lingling__huabian"] = "猾变",
  [":lingling__huabian"] = "出牌阶段限一次，你可以令一名其他角色将一张牌当【火攻】对你使用，若造成伤害，你可以交给其一张牌并回复1点体力，"..
  "若未造成伤害且其手牌多于两张，其交给你一张牌。",

  ["#lingling__huabian"] = "猾变：令一名角色将一张牌当【火攻】对你使用",
  ["#lingling__huabian-use"] = "猾变：请将一张牌当【火攻】对 %src 使用",
  ["#lingling__huabian1-give"] = "猾变：你可以交给 %dest 一张牌，回复1点体力",
  ["#lingling__huabian2-give"] = "猾变：请交给 %src 一张牌",
}

huabian:addEffect("active", {
  anim_type = "control",
  prompt = "#lingling__huabian",
  card_num = 0,
  target_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(huabian.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, player, to_select, selected, selected_cards)
    return #selected == 0 and to_select ~= player and not to_select:isNude()
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    local use = room:askToUseVirtualCard(target, {
      name = "fire_attack",
      skill_name = huabian.name,
      prompt = "#lingling__huabian-use:"..player.id,
      cancelable = false,
      extra_data = {
        exclusive_targets = { player.id },
      },
      card_filter = {
        n = 1,
      },
    })
    if not player.dead and not target.dead then
      if use and use.damageDealt then
        if not player:isNude() then
          local card = room:askToCards(player, {
            min_num = 1,
            max_num = 1,
            include_equip = true,
            skill_name = huabian.name,
            prompt = "#lingling__huabian1-give::"..target.id,
            cancelable = true,
          })
          if #card > 0 then
            room:moveCardTo(card, Card.PlayerHand, target, fk.ReasonGive, huabian.name, nil, false, player)
            if not player.dead then
              room:recover{
                who = player,
                num = 1,
                recoverBy = player,
                skillName = huabian.name,
              }
            end
          end
        end
      elseif target:getHandcardNum() > 2 then
        local card = room:askToCards(target, {
          min_num = 1,
          max_num = 1,
          include_equip = true,
          skill_name = huabian.name,
          prompt = "#lingling__huabian2-give:"..player.id,
          cancelable = false,
        })
        room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonGive, huabian.name, nil, false, target)
      end
    end
  end,
})

return huabian
